package cn.indi.zyj.member.test;


import cn.indi.zyj.common.context.LoginMemberContext;
import cn.indi.zyj.common.resp.CommonResp;
import cn.indi.zyj.common.resp.PageResp;
import cn.indi.zyj.member.req.PassengerQueryReq;
import cn.indi.zyj.member.req.PassengerSaveReq;
import cn.indi.zyj.member.resp.PassengerQueryResp;
import cn.indi.zyj.member.service.PassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/passenger")
public class PassengerController {

    @Resource
    private PassengerService passengerService;


    @PostMapping("/save")
    public CommonResp<Object> save(@Valid @RequestBody PassengerSaveReq passengerSaveReq){
        passengerService.save(passengerSaveReq);
        return new CommonResp<>();
    }

    @GetMapping("/queryList")
    public CommonResp<PageResp<PassengerQueryResp>> queryList(@Valid PassengerQueryReq passengerQueryReq) {
        passengerQueryReq.setMemberId(LoginMemberContext.getId());
        return new CommonResp<>(passengerService.queryList(passengerQueryReq));
    }


    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id){
        passengerService.delete(id);
        return new CommonResp<>();
    }

    @GetMapping("/query-mine")
    public CommonResp<List<PassengerQueryResp>> queryMine() {
        return new CommonResp<>(passengerService.queryMine());
    }



}
